#ifndef CEditH
#define CEditH

#include <SysUtils.hpp>
#include <Controls.hpp>
#include <Classes.hpp>
#include <Forms.hpp>
#include <StdCtrls.hpp>
#include <system.hpp>
#include <WinUser.h>
#include "CtrlStd.h"
#include "Messages.h"

#define ECART_LIBEL_EDIT    10
#define TOP_LIBELLE         3

namespace Cedit
{

class PACKAGE_CTRLSTD CCustomEdit : public TCustomMemo
{
 private:
  typedef TCustomMemo inherited;
  typedef void __fastcall (__closure* TIllegalCharEvent)       ( CCustomEdit* pedSender, Word& cIllegalCharCode, bool& bAccept);
  typedef void __fastcall (__closure* TIllegalPasteEvent)      ( CCustomEdit* pedSender, AnsiString& strClipText, bool& bAccept);

 public:
  typedef enum { feAlpha, feNumerique, feBlanc, feTotal} FiltreEdit;
  typedef Set< FiltreEdit, feAlpha, feTotal>             FiltresEdit;

 private:
  bool                      FFlechesChangentFocus;
  AnsiString                FLibelle;
  TLabel*                   LLibelle;
  TFont*                    FLibelleFont;
  int                       FSizeEsp;            // Taille entre le libelle et l'edit
  UINT                      m_uMaxChars;         // Nb max de caractères éditables dans le contrôle (0 = illimité) Doit être utilisé à la place de MaxLength pour éviter des récursions infinies
  FiltresEdit               m_feFiltres;         // Filtres à appliquer en saisie
  TIllegalCharEvent         m_pfnOnIllegalChar;  // Evénement d'un caractère illegal frappé (i.e. que le filtre à rejeté)
  TIllegalPasteEvent        m_pfnOnIllegalPaste; // Evénement de collage (via presse-papiers) illegal
  bool                      FTabStop;
  bool                      FReadOnly;
  bool                      FObligatoire;
  bool                      FBleuSiHint;
  TCorrectementRempliEvent  m_pfnOnEstCorrectementRempli;
  // Variables temp pour eliminer le Ctrl + Entree
  AnsiString    aOldText;
  int         iOldSelPos;
  int         iOldSelLength;

 private:
  void   __fastcall SetEnabled(     bool              bEnabled  );
  void   __fastcall SetLibelle( const AnsiString      aLibelle  );
  void   __fastcall SetLibelleFont( TFont*            FFont    );
  void   __fastcall SetReadOnly(    bool              bReadOnly );
  void   __fastcall SetSizeEsp(     int               iSizeEsp  );
  void   __fastcall SetVisible(     bool              bVisible  );
  void   __fastcall SetFiltres(     const FiltresEdit feFiltres );
  void   __fastcall SetTabStop(     bool              bTabStop  );
  void   __fastcall SetObligatoire( bool              bObligatoire);
  void   __fastcall SetBleuSiHint( bool               bBleuSiHint);
  void   __fastcall SetShowHint(     bool             bShowHint  );

  bool   __fastcall GetEnabled();
  TFont* __fastcall GetLibelleFont() const;
  bool   __fastcall GetReadOnly() const;
  bool   __fastcall GetVisible() const;
  bool   __fastcall GetTabStop() const;
  AnsiString __fastcall GetText();
  void __fastcall SetText(AnsiString aText);
  bool   __fastcall GetShowHint() const;
  AnsiString __fastcall GetHint();
  void __fastcall SetHint(AnsiString aHint);
  void __fastcall ReplaceLibelle()
    {
      LLibelle->Left = Left - (FSizeEsp >= 0 ? LLibelle->Width + FSizeEsp : -FSizeEsp);
      LLibelle->Top = Top - (LLibelle->Height - Height) / 2;
    }

  protected:
  // Evenements servant a eliminer le Ctrl + Entree
  DYNAMIC void __fastcall KeyDown(Word &Key, Classes::TShiftState Shift);
  DYNAMIC void __fastcall KeyUp(Word &Key, Classes::TShiftState Shift);
  DYNAMIC void __fastcall Change(void);

  __published:
  // Propriétés redéfinies
     __property Color;
  __property bool Enabled     = { read = GetEnabled   , write = SetEnabled    , default = true };
  __property bool ReadOnly    = { read = GetReadOnly  , write = SetReadOnly   , default = false};
  __property bool Visible     = { read = GetVisible   , write = SetVisible    , default = true };
  __property bool TabStop     = { read = GetTabStop   , write = SetTabStop    , default = true };
  __property      ParentColor = {stored = false}; //Propriété à supprimer (stored = false ajouté le 09/05/2005)

  __property AnsiString Text  = { read = GetText      , write = SetText                        };
  __property bool ShowHint    = { read = GetShowHint  , write = SetShowHint   , default = false};
  __property AnsiString  Hint = { read = GetHint      , write = SetHint                        };

  // Nouvelles propriétés
  __property bool        FlechesChangentFocus = {read = FFlechesChangentFocus, write = FFlechesChangentFocus, default = true     };
  __property AnsiString  Libelle              = {read = FLibelle,              write = SetLibelle                                };
  __property TFont*      LibelleFont          = {read = GetLibelleFont,        write = SetLibelleFont                            };
  __property int         SizeEspace           = {read = FSizeEsp,              write = SetSizeEsp,    default = ECART_LIBEL_EDIT };
  __property bool        Obligatoire          = {read = FObligatoire,          write = SetObligatoire,default = false            };

  __property TCorrectementRempliEvent OnEstCorrectementRempli = { read = m_pfnOnEstCorrectementRempli, write = m_pfnOnEstCorrectementRempli};
  __property bool        BleuSiHint           = {read = FBleuSiHint,           write = SetBleuSiHint, default = false            };

 protected:
  // Nouvelles propriétés
  __property FiltresEdit Filtres      = { read = m_feFiltres,    write = SetFiltres,    default = 0                };

  // Nouveaux événements
  __property TIllegalCharEvent        OnIllegalChar           = { read = m_pfnOnIllegalChar,        write = m_pfnOnIllegalChar};
  __property TIllegalPasteEvent       OnIllegalPaste          = { read = m_pfnOnIllegalPaste,       write = m_pfnOnIllegalPaste};

  bool __fastcall IsStringValid( const char* pcsz) const;
  void            __fastcall LibelleFontChange( TObject*  Sender );
  virtual void    __fastcall WndProc(           TMessage& Message );
  virtual void    __fastcall CreateParams(Controls::TCreateParams &Params);

 public:
  virtual inline bool       __fastcall IsEmpty( void) { return( GetTextLen() == 0);}
  AnsiString __fastcall SolveSelection( DWORD& dwCaretPos0); // Retourne le texte du control sans la sélection courante
  virtual bool __fastcall EstCorrectementRempliDefault( void);

 protected:
  // Types de paramètres de messages
  struct TEMLimitText {
   Cardinal Msg;
   UINT     uMaxChars;
   LPARAM   lUnused;
   long     lDummyResult;
   };

  // Déclaration des messages
  void __fastcall WMSetText(   Messages::TWMSetText&   Msg);
  void __fastcall EMLimitText( TEMLimitText&           Msg);
  void __fastcall WMChar(      Messages::TWMChar&      Msg);
  void __fastcall WMPaste(     Messages::TWMPaste&     Msg);

  // Déroutement des messages
  BEGIN_MESSAGE_MAP
   MESSAGE_HANDLER( WM_SETTEXT,    TWMSetText,   WMSetText)   // via Text
   MESSAGE_HANDLER( EM_LIMITTEXT,  TEMLimitText, EMLimitText) // via MaxLength
   MESSAGE_HANDLER( WM_CHAR,       TWMChar,      WMChar)
   MESSAGE_HANDLER( WM_PASTE,      TWMPaste,     WMPaste)
  END_MESSAGE_MAP( inherited)

 public:
  __fastcall CCustomEdit(TComponent* Owner);
  virtual __fastcall ~CCustomEdit();

  static TControl *   __fastcall FindControlUpOrDown( TWinControl *Parent, TWinControl *Ctrl, Word Key );

}; /* class CCustomEdit */

class PACKAGE_CTRLSTD CEdit : public CCustomEdit
{
   private:
      typedef CCustomEdit inherited;

 public:
  __fastcall CEdit( TComponent* pOwner);
  virtual __fastcall ~CEdit(){};

 __published:
  __property Anchors;
  __property Alignment;
  __property AutoSelect;
  __property AutoSize;
  __property BorderStyle;
  __property Color;
  __property CharCase;
  __property Ctl3D;
  __property DragCursor;
  __property DragMode;
  __property Enabled;
  __property Filtres;
  __property Font;
  __property HelpContext;
  __property Hint;
  __property Libelle;
  __property LibelleFont;
  __property MaxLength;
  __property Modified;
  __property OEMConvert;
  __property ParentFont;
  __property ParentShowHint;
  __property PasswordChar;
  __property PopupMenu;
  __property ReadOnly;
  __property ShowHint;
  __property SizeEspace;
  __property TabOrder;
  __property TabStop;
  __property Text;
  __property Visible;

 __published:
  // Publication des événements hérités
  __property OnChange;
  __property OnStartDrag;
  __property OnDragDrop;
  __property OnDragOver;
  __property OnEndDrag;
  __property OnIllegalChar;
  __property OnIllegalPaste;
  __property OnKeyDown;
  __property OnKeyPress;
  __property OnKeyUp;
  __property OnEnter;
  __property OnExit;
  __property OnMouseDown;
  __property OnMouseMove;
  __property OnMouseUp;
  __property OnClick;
  __property OnDblClick;
}; /* class CEdit */
} // namespace Cedit
#ifndef NO_IMPLICIT_NAMESPACE_USE



 using namespace Cedit;
#endif
#endif
